package inl.resilienceManager.qmul.gemom;

import java.util.ArrayList;
import java.util.Arrays;
//import java.util.HashMap;

import resilienceManager.qmul.gemom.Gbroker;

/** COPYRIGHT DISCLAIMER
 * Synopsis: All the source codes presented in this document are intellectual
 * properties of Queen Mary, University of London.
 * 
 * @year 2010
 * @author Peng Jiang, John Bigham, Jiayi Wu Jinfu Wang------------QMUL
 * @version 1.0 
 * */

public class Sols {
//	a wrapper of solution[]
	
//	TODO add context in solution
//	Context con; 
//	used as primary key in db.sol,
	private int[] solkey;
	solution[] ss;
//	construct db
	private int[] brokerIDs;
	
	public Sols(Gbroker[] gbs, Gbroker[] deadbs){
		this.ss=ss;
		brokerIDs= new int[gbs.length];
		solkey= new int[gbs.length];
		Arrays.fill(solkey, 1);
		for (int i=0; i<gbs.length; i++){
			brokerIDs[i]=gbs[i].getID();
		}
		Arrays.sort(brokerIDs);
		for (Gbroker d: deadbs){
			for (int i=0; i<brokerIDs.length; i++){
				if(brokerIDs[i]==d.getID()){
					solkey[i]=0;
				}
			}
		}
	}
	
	public Sols(Gbroker[] gbs, Gbroker[] deadbs, solution[] ss){
		this.ss=ss;
		brokerIDs= new int[gbs.length];
		solkey= new int[gbs.length];
		Arrays.fill(solkey, 1);
		for (int i=0; i<gbs.length; i++){
			brokerIDs[i]=gbs[i].getID();
		}
		Arrays.sort(brokerIDs);
		for (Gbroker d: deadbs){
			for (int i=0; i<brokerIDs.length; i++){
				if(brokerIDs[i]==d.getID()){
					solkey[i]=0;
				}
			}
		}
	}
	
	
	
	public Sols(Gbroker[] gbs, solution[] ss){
		this.ss=ss;
		brokerIDs= new int[gbs.length];
		solkey= new int[gbs.length];
		Arrays.fill(solkey, 1);
//		for (int i=0; i<gbs.length; i++){
//			brokerIDs[i]=gbs[i].getID();
//		}
//		Arrays.sort(brokerIDs);
//		for (Gbroker d: deadbs){
//			for (int i=0; i<brokerIDs.length; i++){
//				if(solkey[i]==d.getID()){
//					solkey[i]=0;
//				}
//			}
//		}
	}
	
	
	public solution[] getSol(){
		return ss;
	}
	
	public String getSolKey(){
		return getString(solkey);
	}
	
	public static String getString(int[] a){
		String s= "";
		for (int i :a ){
			s=s.concat(String.valueOf(i));
//			s=s+i;
		}
		return s;
	}
	
}
